<template>
  <div
               v-loading="loading"
               element-loading-text="正在初始化页面...">
    <olTable v-bind="$attrs" @initOk="$emit('initOk',$event)" ref="tableModel" v-if="theme == 1" :uuid="uuid" :init-data-source="false"
             theme="t1">
      <template v-for='item in Object.keys($slots)' v-slot:[item]>
        <slot :name="item"></slot>
      </template>
    </olTable>
    <otTopBottom v-bind="$attrs" ref="tableModel" v-if="theme == 2" :uuid="uuid">
      <template v-for='item in Object.keys($slots)' v-slot:[item]>
        <slot :name="item"></slot>
      </template>
    </otTopBottom>
    <OtLeftRight :searchRow="searchRow" v-bind="$attrs" ref="tableModel" v-else-if="theme == 3" :uuid="uuid">
      <template v-for='item in Object.keys($slots)' v-slot:[item]>
        <slot :name="item"></slot>
      </template>
    </OtLeftRight>
    <OtTop1Bottom2 v-bind="$attrs" ref="tableModel" v-else-if="theme == 4" :uuid="uuid">
      <template v-for='item in Object.keys($slots)' v-slot:[item]>
        <slot :name="item"></slot>
      </template>
    </OtTop1Bottom2>
    <OtTop2Bottom1 :searchRow="searchRow" v-bind="$attrs" ref="tableModel" v-else-if="theme == 5" :uuid="uuid">
      <template v-for='item in Object.keys($slots)' v-slot:[item]>
        <slot :name="item"></slot>
      </template>
    </OtTop2Bottom1>
    <otTop2Bottom2 :searchRow="searchRow" v-bind="$attrs" ref="tableModel" v-else-if="theme == 6" :uuid="uuid">
      <template v-for='item in Object.keys($slots)' v-slot:[item]>
        <slot :name="item"></slot>
      </template>
    </otTop2Bottom2>
    <otLeftTreeRightTable v-bind="$attrs" ref="tableModel" v-else-if="theme == 7" :uuid="uuid" :treeUuid="treeUuid">
      <template v-for='item in Object.keys($slots)' v-slot:[item]>
        <slot :name="item"></slot>
      </template>
    </otLeftTreeRightTable>
  </div>
</template>
<script>
import OtTopBottom from "@/components/table/model/ot-top-bottom.vue";
import OtLeftRight from "@/components/table/model/ot-left-right.vue";
import {get} from "@/utils/http/httpUtils";
import OtTop1Bottom2 from "@/components/table/model/ot-top-1-bottom-2.vue";
import OtTop2Bottom1 from "@/components/table/model/ot-top-2-bottom-1.vue";
import OtTop2Bottom2 from "@/components/table/model/ot-top-2-bottom-2.vue";
import otLeftTreeRightTable from "@/components/table/model/ot-left-tree-right-table.vue";
import AutoHeight from "@/components/auto-height/index.vue";
export default {
  name: 'modelIndex',
  components: {
    AutoHeight,
    OtTopBottom, OtLeftRight, OtTop1Bottom2, OtTop2Bottom1, OtTop2Bottom2, otLeftTreeRightTable
  },
  props: {
    uuid: {required: true},
    http: {}
  }, provide() {
    return {
      tableAll: this.table,
      http: this.http
    }
  },
  data() {
    return {
      cas: 0,
      table: {},
      theme: 0,
      searchRow: 0,
      treeUuid: '',
      loading: true,
    }
  },
  methods: {
    initConfig() {
      this.loading = true;
      get(this.http, "/online/initAll", {uuid: this.uuid}).then(data => {
        this.theme = data.theme;
        this.searchRow = data.searchRow;
        this.treeUuid = data.treeUuid;
        this.doSetDataSource(data);
      }).finally(() => {
        this.loading = false;
      })
    },
    doSetDataSource(data) {
      this.$nextTick(() => {
        if (this.$refs.tableModel) {
          if (data.theme == 1 || data.theme == 7) {
            this.$refs.tableModel.setDataSource(data['t1'])
          } else {
            this.$refs.tableModel.setDataSource(data)
          }
        } else {
          setTimeout(() => {
            this.cas++;
            if (this.cas <= 5) {
              console.log("自旋》" + this.cas)
              this.doSetDataSource(data)
            }
          }, 500)
        }
      })
    }
  }, created() {
    this.initConfig()
  }
}
</script>

<style scoped lang="less">
div {
  height: 100%;
  width: 100%;
}
</style>
